package org.fing.edu.uy.admin.managers;

import org.fing.edu.uy.admin.config.ConfigConstants;
import org.fing.edu.uy.admin.config.MgrAdminConfig;
import org.fing.edu.uy.esbadp.core.constants.JMXServiceConstants;
import org.fing.edu.uy.esbadp.core.entity.DMAdpAdaptationRequirements;
import org.fing.edu.uy.esbadp.core.entity.DMAdpConfigProperties;
import org.fing.edu.uy.esbadp.core.entity.DMAdpEvents;
import org.fing.edu.uy.esbadp.core.entity.DMAdpMonitorMechanisms;
import org.fing.edu.uy.esbadp.core.entity.DMAdpMonitorProperties;
import org.fing.edu.uy.esbadp.core.entity.DMAdpServiceRequirements;
import org.fing.edu.uy.esbadp.core.entity.DMAdpServices;
import org.fing.edu.uy.esbadp.core.entity.DMAdpStrategies;
import org.fing.edu.uy.esbadp.core.utils.JMXManager;

public class MgrAdpManager implements IMgrEsbAdpManager {

	
	private String jmxEsbServerServiceURL;
	private String mBeanEsbServiceName;
	
	private String jmxMotorServiceURL;
	private String mBeanMotorServiceName;
	
	
	
	public MgrAdpManager(){
		jmxEsbServerServiceURL = MgrAdminConfig.getInstance().getMBeanProperty(ConfigConstants.JMXEsbAdpURL);
		mBeanEsbServiceName = JMXServiceConstants.JMXPropertiesLoader;
		
		jmxMotorServiceURL =  MgrAdminConfig.getInstance().getMBeanProperty(ConfigConstants.JMXMotorMonitorURL);
		mBeanMotorServiceName = JMXServiceConstants.JMXMotorPropertiesLoader;
	}
	
	
	@Override
	public void reloadAdpAction() throws Exception {
		Object[] arguments = {  };
		String[] signature = {  };
		// result to return			
		JMXManager.callOperation(jmxEsbServerServiceURL, mBeanEsbServiceName, "reloadAdpAction", arguments, signature);		
	}

	@Override
	public DMAdpServices getAdpServices() throws Exception {
		Object[] arguments = {  };
		String[] signature = {  };
		// result to return	
		DMAdpServices ret  = null;

		Object result = JMXManager.callOperation(jmxEsbServerServiceURL, mBeanEsbServiceName, "getAdpServices", arguments, signature);
		if (result != null) {			
			ret = (DMAdpServices) result;
		} else {			
			//TODO ARREGLAR ESTO.
			System.out.println("Era null");
		}		
		return ret;		
	}

	@Override
	public void reloadAdpServiceRequirements() throws Exception{
		Object[] arguments = {  };
		String[] signature = {  };
		// result to return			
		JMXManager.callOperation(jmxEsbServerServiceURL, mBeanEsbServiceName, "reloadAdpServiceRequirements", arguments, signature);	
		
	}

	@Override
	public DMAdpServiceRequirements getAdpServiceRequirements()throws Exception {
		Object[] arguments = {  };
		String[] signature = {  };
		// result to return	
		DMAdpServiceRequirements ret  = null;

		Object result = JMXManager.callOperation(jmxEsbServerServiceURL, mBeanEsbServiceName, "getAdpServiceRequirements", arguments, signature);
		if (result != null) {			
			ret = (DMAdpServiceRequirements) result;
		} else {			
			//TODO ARREGLAR ESTO.
			System.out.println("Era null");
		}		
		return ret;
	}

	@Override
	public void reloadAdpMonitorMechanism() throws Exception{
		Object[] arguments = {  };
		String[] signature = {  };
		// result to return			
		JMXManager.callOperation(jmxEsbServerServiceURL, mBeanEsbServiceName, "reloadAdpMonitorMechanism", arguments, signature);	
		
	}

	@Override
	public DMAdpMonitorMechanisms getAdpMonitorMechanism() throws Exception {
		Object[] arguments = {  };
		String[] signature = {  };
		// result to return	
		DMAdpMonitorMechanisms ret  = null;

		Object result = JMXManager.callOperation(jmxEsbServerServiceURL, mBeanEsbServiceName, "getAdpMonitorMechanism", arguments, signature);
		if (result != null) {			
			ret = (DMAdpMonitorMechanisms) result;
		} else {			
			//TODO ARREGLAR ESTO.
			System.out.println("Era null");
		}		
		return ret;
	}

	@Override
	public void reloadAdpMonitorProperties()throws Exception {
		Object[] arguments = {  };
		String[] signature = {  };
		// result to return			
		JMXManager.callOperation(jmxEsbServerServiceURL, mBeanEsbServiceName, "reloadAdpMonitorProperties", arguments, signature);	
		
	}

	@Override
	public DMAdpMonitorProperties getAdpMonitorProperties()throws Exception {
		Object[] arguments = {  };
		String[] signature = {  };
		// result to return	
		DMAdpMonitorProperties ret  = null;

		Object result = JMXManager.callOperation(jmxEsbServerServiceURL, mBeanEsbServiceName, "getAdpMonitorProperties", arguments, signature);
		if (result != null) {			
			ret = (DMAdpMonitorProperties) result;
		} else {			
			//TODO ARREGLAR ESTO.
			System.out.println("Era null");
		}		
		return ret;
	}

	@Override
	public void reloadConfigProperties() throws Exception{
		Object[] arguments = {  };
		String[] signature = {  };
		
		JMXManager.callOperation(jmxEsbServerServiceURL, mBeanEsbServiceName, "reloadConfigProperties", arguments, signature);	
		
	}

	
	@Override
	public DMAdpConfigProperties getAdpConfigProperties() throws Exception{
		Object[] arguments = {  };
		String[] signature = {  };
		// result to return	
		DMAdpConfigProperties ret  = null;
				
		Object result = JMXManager.callOperation(jmxEsbServerServiceURL, mBeanEsbServiceName, "getAdpConfigProperties", arguments, signature);
		if (result != null) {			
			ret = (DMAdpConfigProperties) result;
		} else {			
			//TODO ARREGLAR ESTO.
			System.out.println("Era null");
		}		
		return ret;
	}
	
	

	@Override
	public void reloadMonitoredEvents() throws Exception {
		Object[] arguments = {  };
		String[] signature = {  };
		
		JMXManager.callOperation(jmxMotorServiceURL, mBeanMotorServiceName, "reloadMonitoredEvents", arguments, signature);	
		
	}


	@Override
	public DMAdpEvents getAdpEvents() throws Exception {
		Object[] arguments = {  };
		String[] signature = {  };
		// result to return	
		DMAdpEvents ret  = null;

		Object result = JMXManager.callOperation(jmxMotorServiceURL, mBeanMotorServiceName, "adpEvents", arguments, signature);
		if (result != null) {			
			ret = (DMAdpEvents) result;
		} else {			
			//TODO ARREGLAR ESTO.
			System.out.println("Era null");
		}		
		return ret;
	}


	@Override
	public void reloadAdaptationRequirements() throws Exception {
		Object[] arguments = {  };
		String[] signature = {  };
		
		JMXManager.callOperation(jmxMotorServiceURL, mBeanMotorServiceName, "reloadAdaptationRequirements", arguments, signature);	
		
	}


	@Override
	public DMAdpAdaptationRequirements getAdpRequirements() throws Exception {
		Object[] arguments = {  };
		String[] signature = {  };
		// result to return	
		DMAdpAdaptationRequirements ret  = null;

		Object result = JMXManager.callOperation(jmxMotorServiceURL, mBeanMotorServiceName, "adpRequirements", arguments, signature);
		if (result != null) {			
			ret = (DMAdpAdaptationRequirements) result;
		} else {			
			//TODO ARREGLAR ESTO.
			System.out.println("Era null");
		}		
		return ret;
	}


	@Override
	public void reloadStrategies() throws Exception {
		Object[] arguments = {  };
		String[] signature = {  };
		
		JMXManager.callOperation(jmxMotorServiceURL, mBeanMotorServiceName, "reloadStrategies", arguments, signature);	
		
	}


	@Override
	public DMAdpStrategies getAdpStrategies() throws Exception {
		Object[] arguments = {  };
		String[] signature = {  };
		// result to return	
		DMAdpStrategies ret  = null;
		
		
		Object result = JMXManager.callOperation(jmxMotorServiceURL, mBeanMotorServiceName, "adpStrategies", arguments, signature);
		if (result != null) {			
			ret = (DMAdpStrategies) result;
		} else {			
			//TODO ARREGLAR ESTO.
			System.out.println("Era null");
		}		
		return ret;
	}


	public String getmBeanEsbServiceName() {
		return mBeanEsbServiceName;
	}


	public void setmBeanEsbServiceName(String mBeanEsbServiceName) {
		this.mBeanEsbServiceName = mBeanEsbServiceName;
	}


	public String getjmxEsbServerServiceURL() {
		return jmxEsbServerServiceURL;
	}


	public void setjmxEsbServerServiceURL(String jmxEsbServerServiceURL) {
		this.jmxEsbServerServiceURL = jmxEsbServerServiceURL;
	}

	
	public String getJmxMotorServiceURL() {
		return jmxMotorServiceURL;
	}


	public void setJmxMotorServiceURL(String jmxMotorServiceURL) {
		this.jmxMotorServiceURL = jmxMotorServiceURL;
	}


	public String getmBeanMotorServiceName() {
		return mBeanMotorServiceName;
	}


	public void setmBeanMotorServiceName(String mBeanMotorServiceName) {
		this.mBeanMotorServiceName = mBeanMotorServiceName;
	}
	
	
}
